using DotNetNinjaLibrary;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System;

namespace RenderEngine
{
	public class Render
	{
		GameController controller;

		Dictionary<string, ModelRender> models;

		Matrix world;

		public Render(GameController theController)
		{
			controller = theController;
			world = Matrix.Identity;
		}

		public void LoadContent(ContentManager content)
		{
			models = new Dictionary<string, ModelRender>();
			ModelRender modelRender;

			modelRender = new BasicModelRender(content.Load<Model>("TrainingRoom"));
			models.Add("TrainingRoom", modelRender);

			modelRender = new BasicModelRender(content.Load<Model>("IslandArena"));
			models.Add("IslandArena", modelRender);

			modelRender = new SkinnedModelRender(content.Load<Model>("DotNetNinjaModel"));
			models.Add("DotNetNinja", modelRender);

			modelRender = new SkinnedModelRender(content.Load<Model>("GreenMonsterModel"));
			models.Add("GreenMonster", modelRender);

			modelRender = new SkinnedModelRender(content.Load<Model>("HunchbackModel"));
			models.Add("Hunchback", modelRender);
		}

		public void Draw(GameTime gametime, ref Matrix view, ref Matrix projection)
		{

			foreach (Unit unit in controller.Units)
			{
				ModelRender model = models[unit.Model]; // unit.Model
				Vector3 location = new Vector3(unit.Location.X, unit.Location.Y, 0); // Unit location should be passed as refference here
				Matrix.CreateTranslation(ref location, out world);
				model.Draw(gametime, ref view, ref projection, ref world);
			}
		}
	}
}
